package com.atguigu.educms.controller;


import com.atguigu.commonutils.R;
import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * 后台管理使用
 * </p>
 *
 * @author wxc
 * @since 2021-07-07
 */
@RestController
@RequestMapping("/educms/banneradmin")
public class BannerAdminController {

    @Autowired
    private CrmBannerService bannerService;

    //1、分页查询banner
    @GetMapping("/pageBanner/{current}/{limit}")
    public R pageBanner(@PathVariable Long current, @PathVariable Long limit){
        Page<CrmBanner> page = new Page<>(current, limit);
        bannerService.page(page, null);
        return R.ok().data("items", page.getRecords()).data("total", page.getTotal());
    }

    //2、添加banner
    @PostMapping("/addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        bannerService.save(crmBanner);
        return R.ok();
    }

    //3、修改banner
    @PostMapping("/update")
    public R update(@RequestBody CrmBanner crmBanner){
        bannerService.updateById(crmBanner);
        return R.ok();
    }

    //4、修改banner
    @DeleteMapping("/remove/{id}")
    public R remove(@PathVariable String id){
        bannerService.removeById(id);
        return R.ok();
    }

    //5、根据id查询banner
    @GetMapping("/get/{id}")
    public R get(@PathVariable String id){
        CrmBanner banner = bannerService.getById(id);
        return R.ok().data("item", banner);
    }
}

